//
//  NSObject+Addition.m
//  HHDBaseDemo
//
//  Created by 任辰东 on 2019/10/22.
//  Copyright © 2019 任辰东. All rights reserved.
//

#import "NSObject+Addition.h"
#import <objc/runtime.h>  //导入运行时

@implementation NSObject (Addition)

+ (NSString *)className {
    return NSStringFromClass([self class]);
}

@end

@implementation NSObject (ChangeUnicode)

+ (NSString*)stringByReplaceUnicode:(NSString*)string{
    
    NSMutableString *convertedString = [string mutableCopy];
    
    [convertedString replaceOccurrencesOfString:@"\\U" withString:@"\\u" options:0 range:NSMakeRange(0, convertedString.length)];
    
    CFStringRef transform = CFSTR("Any-Hex/Java");
    
    CFStringTransform((__bridge CFMutableStringRef)convertedString, NULL, transform,YES);
    
    return convertedString;
    
}

@end

@implementation NSArray (LengUnicode)

+ (void)load {
    method_exchangeImplementations(class_getInstanceMethod([self class],@selector(description)),class_getInstanceMethod([self class],@selector(replaceDescription)));
    
    method_exchangeImplementations(class_getInstanceMethod([self class],@selector(descriptionWithLocale:)),class_getInstanceMethod([self class],@selector(replaceDescriptionWithLocale:)));
    
    method_exchangeImplementations(class_getInstanceMethod([self class],@selector(descriptionWithLocale:indent:)),class_getInstanceMethod([self class],@selector(replaceDescriptionWithLocale:indent:)));
    
}

- (NSString*)replaceDescription {
    
    return[NSObject stringByReplaceUnicode:[self replaceDescription]];
    
}

- (NSString*)replaceDescriptionWithLocale:(nullable id)locale {
    
    return[NSObject stringByReplaceUnicode:[self replaceDescriptionWithLocale:locale]];
    
}

- (NSString*)replaceDescriptionWithLocale:(nullable id)locale indent:(NSUInteger)level {
    
    return [NSObject stringByReplaceUnicode:[self replaceDescriptionWithLocale:locale indent:level]];
}



@end

@implementation NSDictionary (LengUnicode)

+ (void)load {
    
    method_exchangeImplementations(class_getInstanceMethod([self class],@selector(description)),class_getInstanceMethod([self class],@selector(replaceDescription)));
    
    method_exchangeImplementations(class_getInstanceMethod([self class],@selector(descriptionWithLocale:)),class_getInstanceMethod([self class],@selector(replaceDescriptionWithLocale:)));
    
    method_exchangeImplementations(class_getInstanceMethod([self class],@selector(descriptionWithLocale:indent:)),class_getInstanceMethod([self class],@selector(replaceDescriptionWithLocale:indent:)));
    
}

- (NSString*)replaceDescription {
    
    return[NSObject stringByReplaceUnicode:[self replaceDescription]];
    
}

- (NSString*)replaceDescriptionWithLocale:(nullable id)locale {
    
    return[NSObject stringByReplaceUnicode:[self replaceDescriptionWithLocale:locale]];
    
}

- (NSString*)replaceDescriptionWithLocale:(nullable id)locale indent:(NSUInteger)level {
    
    return[NSObject stringByReplaceUnicode:[self replaceDescriptionWithLocale:locale indent:level]];
}

@end


